package MyAdmin.Controller;

import MyFramePro.Domain.ResponseResult;
import MyFramePro.Domain.Vo.ChangeRoleStatusVo;
import MyFramePro.Domain.Vo.MenuVo;
import MyFramePro.Domain.Vo.RoleVo;
import MyFramePro.Service.Impl.RoleServiceImpl;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
//@PreAuthorize("@myPer.hasAuthority('system:role')") //添加权限信息
@RequestMapping(value = "/system/role")
public class SystemRoleController {

    @Resource
    private RoleServiceImpl roleService;

    /**
     * 这里是查询用户列表的功能
     */
    @GetMapping(value = "/list")
    public ResponseResult getRoleList(Integer pageNum,Integer pageSize,String status,String roleName){

        return roleService.getRoleList(pageNum,pageSize,roleName,status);
    }


    /**
     * 这里是改变角色状态的功能
     */
    @PutMapping(value = "/changeStatus")
    public ResponseResult changeRoleStatus(@RequestBody ChangeRoleStatusVo roleStatusVo){

        return roleService.changeRoleStatus(roleStatusVo);
    }


    /**
     * 这里是新增角色的功能
     */
    @PostMapping
    public ResponseResult addRole(@RequestBody RoleVo roleVo){

        return roleService.addRole(roleVo);
    }


    /**
     * 修改角色之    角色信息回显功能
     */
    @GetMapping("/{id}")
    public ResponseResult showRoleInfo(@PathVariable("id") Long id){

        return roleService.showRoleInfo(id);
    }


    /**
     * 这里是更新角色信息的功能
     */
    @PutMapping
    public ResponseResult updateRole(@RequestBody RoleVo roleVo){

        return roleService.updateRole(roleVo);
    }

    /**
     * 这里是删除角色的功能
     */
    @DeleteMapping("{id}")
    public ResponseResult deleteRole(@PathVariable("id") Long roleId){

        return roleService.deleteRole(roleId);
    }


    /**
     * 新增用户————查询角色信息的功能
     */
    @GetMapping(value = "/listAllRole")
    public ResponseResult selectAllRoles(){

        return roleService.selectAllRoles();
    }

}
